# jg.py
""" 拷贝金港文件至指定文件夹，并压缩 """

import os
import shutil


# sourcefilename = "/Users/huxiupeng/Projects/osensoft/*.pbd"
# targetfilepath = "/Users/huxiupeng/Projects/Deploy/jg/"
# 利用系统命令，一般不要使用，会依赖系统
# os.system("cp -f %s %s" % (sourcefilename,targetfilepath))
# shutil.copy(sourcefilename,targetfilepath)
# zipfilename = "/Users/huxiupeng/Projects/Deploy/jgexe.tar.gz"
# zipfolder =  "/Users/huxiupeng/Projects/Deploy/jg/"
# os.system("tar -zcvf %s %s" % (zipfilename,zipfolder))
#
# if os.path.isfile(zipfilename):
# print("压缩成功")


sourcepath = os.path.expanduser(os.path.join('~', 'Projects/osensoft/'))
targetpath = os.path.expanduser(os.path.join('~', 'Projects/Deploy/jg/'))
zippath = os.path.expanduser(os.path.join('~', 'Projects/Deploy/jgexe'))
for file in os.listdir(sourcepath):
    if os.path.splitext(file)[1].lower() == ".pbd":
        sourcefilename = ''.join((sourcepath, file))
        targetfilename = ''.join((targetpath, file))
        shutil.copy2(sourcefilename, targetfilename)
        # print(sourcefilename + "-->" + targetfilename)

zipfilename = shutil.make_archive(zippath, 'gztar', root_dir=targetpath)
if os.path.isfile(zipfilename):
    print("sss")
    print(zipfilename + "压缩成功")
else:
    print("压缩错误ss")
